var app = angular.module("myapp", []);

app.factory("ajaxRequest",function($q){
	var ajaxRequest=function(ajaxFun){
		var deferred = $q.defer();
		
		ajaxFun.success(function(data){
			if(data.code && data.code!=200){
				deferred.reject(data);
				return ;
			}
			deferred.resolve(data);
			
		}).error(function(data){
			console.error(data);
			deferred.reject(data);
		});
		
		return deferred.promise;
	}
	
	return {request:ajaxRequest};
});

//布尔值显示是否
app.filter("booltext", function () {
    return function (inputValue) {
        return inputValue ? "是" : "否";
    }
}).filter("yesnotext",function(){
	return function(inputValue){
		if(inputValue==1){
			return "是";
		}
		
		return "否";
	}
}).filter("enabledisabletext",function(){
	return function(inputValue){
		if(inputValue==1){
			return "启用";
		}
		
		return "停用";
	}
});


function Kalert(msg,title,callbackFun){
	if(callbackFun){
		layer.confirm(msg, {
		    btn: ['确定'], //按钮,
			title:title
		}, function(){
			callbackFun(true);
		}, function(){
			callbackFun(true);
		});
	}else{
		layer.alert(msg, {icon: 6,title:title});;
		if(callbackFun){
			callbackFun();
		}
	}
	
}

function Kconfirm(msg,title,callbackFun){
	 if(callbackFun){
		 layer.confirm(msg, {
			    btn: ['确定','取消'], //按钮,
				title:title
			}, function(index){
				callbackFun(true);
				layer.close(index);
			}, function(){
				callbackFun(false);
			});
	 }else{
		layer.alert(msg, {icon: 6,title:title});
	 }
}